//
// Copyright (C) 2008 Jackson Harper (jackson@ximian.com)

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Grr.Model;

namespace Grr.Web
{
    public class GrurrahPage : GrurrahBasePage
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!IsPostBack)
            {
                Grr.Model.Grurrah g = Grr.Model.Grurrah.QueryForByName(Request.QueryString["g"]);
                Session["CurrentGrurrah"] = g;

                string mode = Request.QueryString["mode"];
                if (mode != null)
                {
                    switch (mode.ToLower())
                    {
                        case "edit":
                            SwitchToEditMode();
                            break;
                        case "create":
                            SwitchToCreateMode();
                            break;
                        case "vacant":
                            SwitchToVacantMode();
                            break;
                        case "read":
                        default:
                            if (g != null)
                                SwitchToReadMode();
                            else
                                SwitchToVacantMode();
                            break;
                    }
                } else if (g == null)
                    SwitchToVacantMode();
            }
        }
        
        protected override bool OnBubbleEvent(object source, EventArgs args)
        {
            GrurrahPageModeChangedEventArgs ce = args as GrurrahPageModeChangedEventArgs;

            if (ce != null)
            {
                switch (ce.Mode)
                {
                    case GrurrahPageMode.Edit:
                        SwitchToEditMode();
                        break;
                    case GrurrahPageMode.Read:
                        SwitchToReadMode();
                        break;
                    case GrurrahPageMode.Create:
                        SwitchToCreateMode();
                        break;
                    case GrurrahPageMode.Vacant:
                        SwitchToVacantMode();
                        break;
                }
            }

            return base.OnBubbleEvent(source, args);
        }

        protected virtual void SwitchToEditMode()
        {
        }

        protected virtual void SwitchToReadMode()
        {
        }

        protected virtual void SwitchToCreateMode()
        {
        }

        protected virtual void SwitchToVacantMode()
        {
        }
    }
}

